package com.xiaomei.manager.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xiaomei.manager.dao.BroadcastMapper;
import com.xiaomei.manager.dao.OrderMapper;
import com.xiaomei.manager.dao.PositionMapper;
import com.xiaomei.manager.service.IBroadcastService;
import com.xiaomei.manager.service.IOrderService;
import com.xiaomei.manager.service.IUserService;
import com.xiaomei.manager.utils.ReturnCode;
import com.xiaomei.manager.web.dto.CountDto;
import com.xiaomei.manager.web.dto.RespBody;
import com.xiaomei.manager.web.dto.req.DayCompleteDto;
import com.xiaomei.manager.web.dto.req.FemaleDto;
import com.xiaomei.manager.web.dto.req.QuantityDto;


@Controller
public class CountController {
	@Autowired
	private IUserService iUserService;
	@Autowired
	private OrderMapper OrderMapper;
	@Autowired
	private PositionMapper positionMapper;
	@Autowired
	private BroadcastMapper broadcastMapper;
	@Autowired
	private  IOrderService iOrderService;
	/**
	 * 数据统计
	 * @return
	 */
	@RequestMapping(value="count/init",method={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public RespBody getBroadcast(){
		CountDto dto=new CountDto();
		dto.setUserCount(iUserService.selectCount().getUserCount());
		dto.setBroadcastCount(broadcastMapper.selectBroadcastCount().getBroadcastCount());
		dto.setOnLineCount(positionMapper.selectOnLineCount().getOnLineCount());
		dto.setOrderCount(OrderMapper.selectOrderCount().getOrderCount());
		return new RespBody(ReturnCode.CODE_0,RespBody.RESPBODY_DATA_TYPE_OBJECT,dto);
		
	}
	/**
	 * 获取日下单量
	 * @return
	 */
	@RequestMapping(value="get/quantity_count",method={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public RespBody getQuantityCount(String startTime,String endTime){
		List<QuantityDto> quantityCount = iOrderService.getQuantityCount(startTime, endTime);
		return new RespBody(ReturnCode.CODE_0,RespBody.RESPBODY_DATA_TYPE_ARRAY,quantityCount);
		
	}
	/**
	 * 获取日乘单量
	 * @return
	 */
	@RequestMapping(value="get/complete_count",method={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public RespBody getCompleteCount(String startTime,String endTime){
		List<DayCompleteDto> completeCount = iOrderService.selectCompleteCount(startTime, endTime);
		return new RespBody(ReturnCode.CODE_0,RespBody.RESPBODY_DATA_TYPE_ARRAY,completeCount);
		
	}
	/**
	 * 用户增长
	 * @return
	 */
	@RequestMapping(value="get/user",method={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public RespBody getUserCount(String startTime,String endTime,String sex){
		List<FemaleDto> selectFemaleCount = iUserService.selectFemaleCount(startTime, endTime, sex);
		return new RespBody(ReturnCode.CODE_0,RespBody.RESPBODY_DATA_TYPE_ARRAY,selectFemaleCount);
		
	}
}
